﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Nhahang : System.Web.UI.Page
{
    public decimal totalPage { get; set; }
    public int row = 12;
    public int currentPage = 1;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            Load_HomeSlide();
        GetTopNhaHangHot();
        Get5Res();
        totalPage = Count_Page();
        if (Request.QueryString["page"] != null)
        {
            currentPage = Convert.ToInt32(Request.QueryString["page"]);
        } 
    }
    protected void Load_HomeSlide()
    {

        SQLHelper Dal = new SQLHelper();
        Dal.CommandType = CommandType.StoredProcedure;
        Dal.CommandText = "SP_GetResSlide";
        DataTable db = Dal.GetDataTable();
        Repeater1.DataSource = db;
        Repeater1.DataBind();
        Repeater3.DataSource = db;
        Repeater3.DataBind();

    }
    protected void GetTopNhaHangHot()
    {
        //try
        //{
        SQLHelper Dal = new SQLHelper();
        Dal.CommandType = CommandType.StoredProcedure;
        Dal.CommandText = "SP_GetNhaHangByPage";
        Dal.ParameterCollection = new string[] { "@page", "@row" };
        int page = 0;
        if (Request.QueryString["page"] != null)
        {
            page = Convert.ToInt32(Request.QueryString["page"]) - 1;
        }
        Dal.ValueCollection = new string[] { page.ToString(), "12" };
        DataTable db = Dal.GetDataTable();
        rptRes.DataSource = db;
        rptRes.DataBind();
        //}
        //catch
        //{
        //    Response.Redirect("~/Error.aspx");
        //}
    }
    protected void Get5Res()
    {
        SQLHelper Dal = new SQLHelper();
        Dal.Open();
        Dal.CommandType = CommandType.StoredProcedure;
        Dal.CommandText = "SP_GetTop5NhaHangHot";
        DataTable db = Dal.GetDataTable();
        Repeater2.DataSource = db;
        Repeater2.DataBind();
    }
    protected int Count_Page()
    {
        SQLHelper Dal = new SQLHelper();
        Dal.Open();
        Dal.CommandType = CommandType.StoredProcedure;
        Dal.CommandText = "SP_CountNhaHang";
        int result = Convert.ToInt32(Dal.ExecuteScalar());
        return result;

    }
}
